﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>会员列表-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../static/css/font.css">
    <link rel="stylesheet" href="../../../static/css/weadmin.css">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
    <div class="weadmin-nav">
        <span class="layui-breadcrumb" style="visibility: visible;">
            <a href="#">首页</a><span lay-separator="">/</span>
            <a href="#">基础数据设置</a><span lay-separator="">/</span>
            <a><cite>培训试题管理</cite></a>
        </span>
        <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon" style="line-height:30px">&#x1002;</i>
        </a>
    </div>
    <div class="weadmin-body">
        <form class="layui-form">
            <div class="layui-form-item">
                <div class="layui-row">
                    所属类别:
                    <div class="layui-inline">
                        <select id="FTID" name="FTID" class="valid"></select>
                    </div>
                    知识点:
                    <div class="layui-inline">
                        <select id="KKID" name="KKID" class="valid"></select>
                    </div>
                    题型:
                    <div class="layui-inline">
                        <select id="QueType" name="QueType" lay-verify="">
                            <option value=""></option>
                            <option value="1">选择题</option>
                            <option value="2">判断题</option>
                        </select>
                    </div>
                </div>
            </div>
        </form>

        <button class="layui-btn" id="sreach"><i class="layui-icon">&#xe615;  查询</i></button>
        <table id="datalist" lay-filter="datalist"></table>
         
    </div>
    <script src="../../../lib/layui/layui.js" charset="utf-8"></script>
    <script src="../../../static/js/common.js" charset="utf-8"></script>
    <script type="text/html" id="toolbar">
        <div class="layui-btn-container">
            <!--<button class="layui-btn layui-btn-sm" lay-event="delAll"><i class="layui-icon"></i>批量删除</button>
            <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon"></i>添加</button>-->
            <button class="layui-btn layui-btn-sm" lay-event="addList"><i class="layui-icon"></i>批量添加</button>
        </div>
    </script>
    <script type="text/html" id="tool">
        <!--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
    </script>
    <script>
        layui.use(['table', 'jquery', 'layer', 'form'], function () {
            var table = layui.table,
                form = layui.form,
                $ = layui.jquery,
                layer = layui.layer;
            $.support.cors = true;
            $.ajaxSetup({
                cache: false,
                headers: {
                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                },
            })
            //加载文件所属类型
            $.ajax({
                url: ApiUrl + "TrainFileType/Sel",
                type: 'post',
                headers: {
                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                },
                success: function (data) {
                    if (data.StatusCode == 200) {
                        $("#FTID").append("<option value=''></option>");
                        $(data.Data).each(function (index, item) {
                            $("#FTID").append("<option value='" + item.FTID + "'>" + item.FTName + "</option>");
                        });
                        form.render();//必须，不然动态加载项不显示
                    }
                    else if (data.StatusCode == 403) {
                        layer.alert(data.Info, function () {
                            location.href = './login.html';
                        })
                    }
                    else {
                        layer.msg(data.Info);
                    }
                }
            });

            //加载文件所属知识点
            $.ajax({
                url: ApiUrl + "TrainFileKnowledgeKey/SelList",
                type: 'post',
                headers: {
                    "userid": JSON.parse(window.localStorage.authInfo).UserId,
                    "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                },
                success: function (data) {
                    if (data.StatusCode == 200) {
                        $("#KKID").append("<option value=''></option>");
                        $(data.Data).each(function (index, item) {
                            $("#KKID").append("<option value='" + item.KKID + "'>" + item.KKName + "</option>");
                        });
                        form.render();//必须，不然动态加载项不显示
                    }
                    else if (data.StatusCode == 403) {
                        layer.alert(data.Info, function () {
                            location.href = './login.html';
                        })
                    }
                    else {
                        layer.msg(data.Info);
                    }
                }
            });
            function showList() {
                var swhere = JSON.stringify({
                    FTID: $("#FTID").val(),
                    KKID: $("#KKID").val(),
                    QueType: $("#QueType").val(),
                });
                table.render({
                    id: "datalist",
                    elem: '#datalist',
                    url: ApiUrl + 'TrainQuestion/Search', //数据接口,
                    where: { swhere: swhere },
                    cellMinWidth: 80,
                    toolbar: "#toolbar",
                    cols: [
                        [
                            { type: 'checkbox' },
                            { field: 'TQID', title: 'TQID', hide: true },
                            { field: 'FTName', title: '问题类型', width: 100 },
                            { field: 'KKName', title: '知识点', width: 100 },
                            { field: 'Question', title: '题目'},
                            { field: 'OptionA', title: '选项A', width: 120},
                            { field: 'OptionB', title: '选项B', width: 120},
                            { field: 'OptionC', title: '选项C', width: 120 },
                            { field: 'OptionD', title: '选项D', width: 120},
                            { field: 'Answer', title: '答案', width: 65 },
                            { field: 'QueValue', title: '分值', width: 65 },
                            {
                                field: 'QueType', title: '题型', width: 75, templet: function (d) {
                                    return d.QueType==1?'选择题':'判断题';
                                }
                            }
                            
                        ]
                    ],
                    parseData: function (res) { //res 即为原始返回的数据
                        return {
                            "code": res.StatusCode, //解析接口状态
                            "msg": res.Info, //解析提示文本
                            "count": res.Count, //解析数据长度
                            "data": res.Data //解析数据列表
                        };
                    },
                    response: { statusCode: 200 },//规定成功的状态码，默认：0
                    event: true,
                    page: true
                });
            }
            //监听事件
            table.on('toolbar(datalist)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                switch (obj.event) {
                    case 'delAll':
                        if (checkStatus.data.length > 0) {
                            var EIDs = "";
                            for (var i = 0; i < checkStatus.data.length; i++) {
                                EIDs += checkStatus.data[i].TQID + ",";
                            }
                            EIDs = EIDs.substring(0, EIDs.length - 1);
                            $.ajax({
                                url: ApiUrl + "TrainQuestion/DelList",
                                type: 'get',
                                cache: false,
                                data: { delidlist: EIDs },
                                success: function (data) {
                                    if (data.StatusCode == 200 && data.Count != 0) {
                                        layer.alert(data.Info, { icon: 6 }, function (index) {
                                            layer.close(index);
                                            location.reload();
                                        })
                                    }
                                    else if (data.StatusCode == 403) {
                                        top.layer.alert(data.Info + ",请重新登录！", { closeBtn: 0 }, function () {
                                            top.location.href = "http://" + top.location.host + "/login.html";
                                        })
                                    }
                                    else {
                                        layer.msg(data.Info);
                                    }
                                }
                            });
                        }
                        else {
                            layer.msg("未找到勾选项！");
                        }
                        break;
                    case 'add':
                        var add = layer.open({
                            type: 2,
                            title: "人员信息添加",
                            area: ['700px', '450px'],
                            fixed: false, //不固定
                            maxmin: true,
                            content: './trainquestion_add.html',
                            end: function () {
                                location.reload();
                            }
                        });
                        layer.full(add);
                        break;
                    case 'addList':
                        if (checkStatus.data.length > 0) {
                            var EIDs = "";
                            for (var i = 0; i < checkStatus.data.length; i++) {
                                EIDs += checkStatus.data[i].TQID + ",";
                            }
                            EIDs = EIDs.substring(0, EIDs.length - 1);
                            $.ajax({
                                url: ApiUrl + "TrainFileQuestion/AddList",
                                type: 'get',
                                cache: false,
                                data: { TFID:getUrlParam("TFID"),TQIDList:EIDs},
                                success: function (data) {
                                    if (data.StatusCode == 200 && data.Count != 0) {
                                        layer.alert(data.Info, { icon: 6 }, function (index) {
                                            layer.close(index);
                                            parent.layer.closeAll();
                                        })
                                    }
                                    else if (data.StatusCode == 403) {
                                        top.layer.alert(data.Info + ",请重新登录！", { closeBtn: 0 }, function () {
                                            top.location.href = "http://" + top.location.host + "/login.html";
                                        })
                                    }
                                    else {
                                        layer.msg(data.Info);
                                    }
                                }
                            });
                        }
                        else {
                            layer.msg("未找到勾选项！");
                        }
                        break;
                };
            });
            $(function () {
                showList();
                $("#sreach").click(function () {
                    showList();
                })
            })
        });
    </script>
</body>
</html>